
cc.Class({
    extends: cc.Component,

    properties: {
        pNode: cc.Node,

        winFlag: cc.Node,
        loseFlag: cc.Node,
        mjprefab: cc.Prefab,
        LiuJuStye: cc.Node,
        DianPaoStye: cc.Node,
        ZiMoStye: cc.Node,
        WinPai: cc.Node,
        iswin: {
            get() { return this.winFlag && this.winFlag.active; },
            set(n) {
                this.winFlag && (this.winFlag.active = n);
                this.loseFlag && (this.loseFlag.active = !n);
            }
        }
    },


    start() {

    },
    makeMj(n, show = false) {
        let mj = cc.instantiate(this.mjprefab);
        let reslogic = mj.getComponent('MajiangRes');
        reslogic.dir = this._dir;
        reslogic.majiang = n;
        reslogic.isStand = false;
        reslogic.isShow = show;
        return mj
    },



    setPlayerDatas(list, winid, lose, lastmj) {
        if (lose == 0 && winid != 0 ) {
            this.ZiMoStye.active = true;
            this.DianPaoStye.active = false;
            this.LiuJuStye.active = false;
            this.WinPai.active = true;
            let reslogic = this.WinPai.getChildByName('MaJiang').getComponent('MajiangRes');
            reslogic.majiang = lastmj;
        } else if (winid == 0) {
            this.ZiMoStye.active = false;
            this.DianPaoStye.active = false;
            this.LiuJuStye.active = true;
            this.WinPai.active = true;
            let reslogic = this.WinPai.getChildByName('MaJiang').getComponent('MajiangRes');
            reslogic.majiang = lastmj;
        } else {
            this.ZiMoStye.active = false;
            this.DianPaoStye.active = true;
            this.LiuJuStye.active = false;
            this.WinPai.active = true;
            let reslogic = this.WinPai.getChildByName('MaJiang').getComponent('MajiangRes');
            reslogic.majiang = lastmj;
        }
        this.node.active = true;
        for (let i = 0; i < list.length; i++) {
            let x = -280;
            let xtype = 300;
            let y = 75;
            let pdata = list[i];
            let pnode = cc.instantiate(this.pNode);
            pnode.active = true;
            pnode.y -= i * (pnode.height + 10);
            pnode.parent = this.pNode.parent;
            let plogic = pnode.getComponent('MajiangResultItem');
            plogic.username = pdata.username;
            plogic.roundscore = pdata.roundscore;
            plogic.score = pdata.score;
            plogic.ZhuangScore = pdata.ZhuangScore;
            plogic.GangScore = pdata.gangscore;
            plogic.QueScore = pdata.QueScore;
            plogic.ShaiScore = pdata.ShaiPaiScore;
            plogic.FengScore = pdata.FengScore;
            plogic.ZhongFaBaiScore = pdata.ZhongFaBaiScore;
            plogic.KaScore = pdata.KaScore;
            if (pdata.userid == cc.ll.player.userid) {
                this.iswin = pdata.roundscore >= 0;
            }
            if (pdata.userid != winid||pdata.userid != lose) {
                plogic.winFlag=false;
                plogic.lose=false;
            }
            if (pdata.userid==winid) {
                plogic.WinSprit.active=true;
            }
            if (pdata.userid==lose) {
                plogic.LoseSprit.active=true;
            }
            //各个的碰杠牌
            for (let index = 0; index < pdata.TypeMaJiangs.length; index++) {
                for (let indexPai = 0; indexPai < pdata.TypeMaJiangs[index].mjs.length; indexPai++) {
                    let majiang = pdata.TypeMaJiangs[index].mjs[indexPai];
                    let mj = this.makeMj(majiang, true);
                    mj.parent = this.node;
                    mj.setScale(0.6, 0.6)
                    // mj.x = xtype - indexPai * 33;
                    xtype -= 33;
                    mj.x = xtype - index * 30;
                    mj.y = y - i * 90;
                }
            }
            //手里的牌
            pdata.HandMaJiangs.sort((a, b) => {
                return a - b;
            });
            for (let j = 0; j < pdata.HandMaJiangs.length; j++) {
                let majiang = pdata.HandMaJiangs[j];
                let mj = this.makeMj(majiang, true);
                mj.parent = this.node;
                mj.setScale(0.6, 0.6)
                mj.x = x + j * 33;
                mj.y = y - i * 90;
            }
        }
    }
});
